热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Python|Pandasindex.get_values()

Python|Pandasindex.get_values()

Python | Pandas index . get _ values()

原文:https://www . geesforgeks . org/python-pandas-index-get _ values/

Python 是进行数据分析的优秀语言,主要是因为以数据为中心的 python 包的奇妙生态系统。 【熊猫】 就是其中一个包,让导入和分析数据变得容易多了。

熊猫 **Index.get_values()**函数以数组形式返回索引数据。对于多索引数组,它返回一维数组。

语法: Index.get_values()

返回:索引值的一维数值数组

示例#1: 使用Index.get_values()函数将索引值作为 numpy 数组返回。

# importing pandas as pd
import pandas as pd
# Creating the Index
idx = pd.Index(['Labrador', 'Beagle', 'Labrador',
                     'Lhasa', 'Husky', 'Beagle'])
# Print the Index
idx

输出:

让我们使用Index.get_values()函数将 Index 数据作为 numpy 数组返回。

# Returns the labels of Index as numpy array
idx.get_values()

输出:

正如我们在输出中看到的,Index.get_values()函数已经将索引标签作为 numpy 数组返回。

示例 2: 在多索引数组上使用Index.get_values()函数。

# importing pandas as pd
import pandas as pd
# Creating the MultiIndex object
midx = pd.MultiIndex.from_arrays([['Mon', 'Tue', 'Wed', 'Thr'],
                   [10, 20, 30, 40]], names =('Days', 'Target'))
# Print the MultiIndex object
midx

输出:

让我们将索引标签返回到一维 numpy 数组格式。

# Convert the multi-index into one
# dimensional numpy array form.
midx.get_values()

输出:

正如我们在输出中所看到的,甚至多索引也被转换成了一维数组形式。


推荐阅读
author-avatar
刘家大宝688
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有